package gold.digger;

import gold.utils.InputUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC581 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findUnsortedSubarray(int[] nums) {
            int[] copyNums = new int[nums.length];
            for (int i = 0; i < nums.length; i++) {
                copyNums[i] = nums[i];
            }

            Arrays.sort(copyNums);
            int left = 0, right = nums.length - 1;
            while (left <= right && copyNums[left] == nums[left]) ++left;
            while (left <= right && copyNums[right] == nums[right]) --right;

            return right - left + 1;
        }
    }

    public void run() {
        Solution solution = new Solution();
        int[] arr = InputUtil.toIntegerArray("[1]");
        System.out.println(solution.findUnsortedSubarray(arr));
    }

    public static void main(String[] args) throws Exception {
        LC581 an = new LC581();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
